﻿using Google.Protobuf;
using System;
using System.Collections.Generic;
using System.Text;
using Cemit.PolyProto;

namespace Cemit.PolyServer
{
    public class Player : IPlayer
    {
        public event Action OnLogout;

        public string ID { get; }

        private ClientState m_ClientSate { get; }

        public Player(ClientState state, string id)
        {
            ID = id;
            m_ClientSate = state;
            m_ClientSate.player = this;
        }

        public IPlayer Send(IMessage message)
        {
            m_ClientSate.Send(message);
            return this;
        }

        /// <summary>
        /// 注销登录
        /// </summary>
        public void Logout()
        {
            OnLogout?.Invoke();
            m_ClientSate.server.Players.RemovePlayer(ID);
        }
    }
}
